#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
typedef pair<LL,LL> PI;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Tree{
    LL l,r,tag;
    LL minval,pos;
}tree[maxn<<2];
inline void push_up(LL p){
     tree[p].minval=min(tree[p<<1].minval,tree[p<<1|1].minval);
     if(tree[p].minval==tree[p<<1].minval){
        tree[p].pos=tree[p<<1].pos;
     }
     else tree[p].pos=tree[p<<1|1].pos;
}
inline void addtag(LL p,LL d){
    tree[p].tag+=d;
    tree[p].minval+=d;
}
inline void push_down(LL p){
    if(tree[p].tag){
        addtag(p<<1,tree[p].tag);
        addtag(p<<1|1,tree[p].tag);
        tree[p].tag=0;
    }
}
inline void build(LL p,LL l,LL r){
     tree[p].l=l;tree[p].r=r;tree[p].minval=1e18;tree[p].tag=0;
     if(l==r){tree[p].pos=l;return;}
     LL mid=(l+r)>>1;
     build(p<<1,l,mid);build(p<<1|1,mid+1,r);
     push_up(p);
}
inline void modify(LL p,LL l,LL r,LL d,bool op){
    if(l<=tree[p].l&&r>=tree[p].r){
        if(!op) tree[p].minval=tree[p].tag=d;
        else addtag(p,d);
        return;
    }
    push_down(p);
    LL mid=(tree[p].l+tree[p].r)>>1;
    if(l<=mid) modify(p<<1,l,r,d,op);
    if(r>mid) modify(p<<1|1,l,r,d,op);
    push_up(p);
}
inline PI query(LL p,LL l,LL r){
    if(l<=tree[p].l&&r>=tree[p].r){
        return PI{tree[p].minval,tree[p].pos};
    }
    push_down(p);
    LL mid=(tree[p].l+tree[p].r)>>1;
    PI ans={1e18,0};
    if(l<=mid) {
        PI res=query(p<<1,l,r);
        if(ans.first>res.first){
                ans=res;
        }
    }
    if(r>mid){
        PI res=query(p<<1|1,l,r);
        if(ans.first>res.first){
                ans=res;
        }
    }
    return ans;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n;cin>>n;
    build(1,1,n);
    for(LL i=1;i<=n;i++){
        LL op;cin>>op;
        if(op==1){
            LL x;cin>>x;
            modify(1,i,i,x,0);
        }
        else if(op==2){
            LL x;cin>>x;
            modify(1,1,i,x,1);
        }
        else if(op==3){
            PI k=query(1,1,i-1);
            cout<<k.first<<endl;
            modify(1,k.second,k.second,1e18,0);
        }
    }

   	return 0;
}
